import { Controller, Get, Post, ApiInfo, JwtUnless } from '@libs/koa-action-decorator/index';
import { ErrorModel, SuccessModel } from '@utils/respond/ResModel';
import { isMobile } from '@utils/is';
import { mobileUserLogin,refreshToken } from '@modules/mobile/mobileUser/services/mobileUserService';

export default @ApiInfo({ name: '后台用户接口', catalogue: '用户管理' })
@Controller('/api/mobile/user')
class mobileUserControllers {
  @Get('/phoneCode')
  @JwtUnless
  @ApiInfo('获取手机验证码')
  async phoneCode(ctx) {
    ctx.body = new SuccessModel({ success: true });
  }

  @Post('/login')
  @JwtUnless
  @ApiInfo('移动端用户登录')
  async mobileUserLogin(ctx) {
    const body = ctx.request.body || {};
    ctx.body = await mobileUserLogin(body,ctx);
  }

  @Get('/refreshToken')
  @ApiInfo('更新用户的token')
  async refreshToken(ctx) {
    const userId = ctx.jwtSession.userId;
    ctx.body = await refreshToken(userId,ctx);
  }
}
